package com.jari.lg.service.profile.carstatistic;

import com.jari.lg.domain.DevBase;
import com.jari.lg.domain.FirstTimeCarEntity;
import com.jari.lg.mapper.FirstTimeCarEntityMapper;
import com.jari.lg.utils.BaseData;
import com.jari.lg.utils.Constants;
import com.jari.lg.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class CarFirstTimeInService {

    @Autowired
    private FirstTimeCarEntityMapper firstTimeCarEntityMapper;

    /*
    *   每分钟每个卡口插入一个记录
    * */
    @Scheduled(cron = "* */1 * * * ?")
    public void makeInfo(){

        List<FirstTimeCarEntity> result = new ArrayList<>();
        FirstTimeCarEntity entity;
        List<DevBase> checkpointList = BaseData.checkpointList;
        for(DevBase dev : checkpointList){
            entity = generate(dev);
            firstTimeCarEntityMapper.insert(entity);
        }
    }

    private FirstTimeCarEntity generate(DevBase devBase){
        FirstTimeCarEntity entity = new FirstTimeCarEntity();
        entity.setPlatenumber(Utils.createPlateNumber());
        entity.setCheckpointcode(devBase.getDevicecode());
        entity.setCheckpointname(devBase.getDevicename());
        entity.setCreator("SYS");
        entity.setDatastatus(Constants.DATA_STATUS_ONE);
        entity.setPlatetype(Utils.createPlateType());
        entity.setDatetime(new Date());
        entity.setGmtcreate(new Date());
        return entity;
    }

}
